<template>
	<view class="title">
		<view class="status-bar"></view>
		<view class="nav-bg">
			<view class="image-bg">
				<image v-if="isShowBack" @click="back" class="back-image-style" src="/static/robot/icon_white_back.png"></image>
				<image v-if="isShowRightMenu" class="clear-img-icon" src="/static/robot/icon_robot_head_menu.png"
					@click="openOrCloseDrawer"></image>
			</view>
			<view class="nav-title">
				<text v-if="!isShowImg" class="nav-title-txt">{{title}}</text>
				<image v-else :src="imgLogo" class="title-img" @click="previewImg"></image>
			</view>
			<!-- <view class="clear-img-bg">
			</view> -->
			<view class="right-tem-list-bg">
				<view v-if="isShowRightTxt" class="right-tem-list-txt" @click="rightToClick">模板列表</view>
			</view>
		</view>
	</view>
</template>

<script>
	import robotApi from '../apis/robotApi';
	export default {
		name:"custom-head",
		data() {
			return {
				imgLogo: "",
				imgList: []
			};
		},
		props: {
			isShowBack: {
				type: Boolean,
				default: true
			},
			isShowImg: {
				type: Boolean,
				default: false
			},
			isShowRightMenu: {
				type: Boolean,
				default: false
			},
			isShowRightTxt: {
				type: Boolean,
				default: false
			},
			title: {
				type: String,
				default: ""
			}
		},
		mounted() {
			this.getLogoUrl()
		},
		methods: {
			back() {
				uni.navigateBack()
			},
			
			getLogoUrl() {
				robotApi.getLogoImgUrl()
					.then(res => {
						if (res.code == 200 || res.code == "200") {
							this.imgLogo = res.data
							this.imgList = [res.data]
						}
					})
			},
			
			previewImg(){
				uni.previewImage({
					urls: this.imgList,
					current: 0
				})
			},
			
			openOrCloseDrawer() {
				this.$emit("openOrCloseDrawer")
			},
			
			rightToClick() {
				this.$emit('rightClick')
			}
		}
	}
</script>

<style scoped lang="scss">
	.title {
		position: sticky;
		z-index: 99;
		box-sizing: border-box;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
	}

	.status-bar {
		box-sizing: border-box;
		display: block;
		width: 100%;
		height: var(--status-bar-height);
		line-height: var(--status-bar-height);
		background: linear-gradient(227deg, #0f172a 0%, #0f172a 100%);
	}

	.nav-bg {
		width: 100%;
		display: flex;
		align-items: center;
		background: linear-gradient(227deg, #0f172a 0%, #0f172a 100%);
		height: 88rpx;
	}

	.image-bg {
		height: 88rpx;
		width: 80rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.back-image-style {
		width: 24px;
		height: 24px;
	}

	.clear-img-bg {
		width: 88rpx;
		height: 80rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.right-tem-list-bg {
		margin-right: 32rpx;
		
		display: flex;
		align-items: center;
	}
	.right-tem-list-txt {
		color: #ffffff;
		font-size: 28rpx;
	}

	.clear-img-icon {
		width: 24px;
		height: 24px;
	}

	.nav-title {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.nav-title-txt {
		font-size: 36rpx;
		color: #ffffff;
	}
	.title-img {
		width: 60rpx;
		height: 60rpx;
		border-radius: 50%;
	}
</style>